# 元组，元素不能被修改 tuple
tuple1 = (1, 2, 3, True, '666')
print(tuple1)
tuple2 = (1)  # 只有一个元素时，解释器将括号认定为数学运算中的括号，解决：加逗号
tuple3 = (1,)
print(type(tuple2), type(tuple3))
# 其他类型转tuple
tuple4 = tuple("hello")
print(tuple4)
tuple5 = tuple([1, 2, 3, 4, 5])
print(tuple5)
# tuple转其他类型
list1 = list(tuple1)
print(list1)
s = str(tuple1)
print(s, type(s))
print("-----------------------------------")

# 序列的通用操作
# 索引
print(tuple1[1])
# 切片
print(tuple1[::-1])
# len
print(len(tuple1))
print(max(tuple5), min(tuple5))
# del
# +
print(tuple1 + tuple4)
# *
print(tuple1 * 3)
# in
print(1 in tuple1)

# 常用方法
num = tuple1.count(1)
print(num)
num2 = tuple1.index(2)
print(num2)

# 元组的遍历
for i in tuple1:
    print(i, end=" ")
print()

print(tuple1)

for i, j in enumerate(tuple1):
    print(i, j)
